/**
 * Copyright 2018 人人开源 http://www.renren.io
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package io.renren.common.aspect;

import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import io.renren.common.config.WebConfig;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 系统日志，切面处理类
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.3.0 2017-03-08
 */
@Aspect
@Component
public class SysAddCreateUserAspect {

	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Pointcut("execution(* io.renren.modules.xm.service..*.update(..))")
	public void updatePointcut(JoinPoint joinPoint){
		//获取目标方法的参数信息
		Object[] obj = joinPoint.getArgs();
//		SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getSession()
//			.getAttribute(WebConfig.LOGIN_USER);
	}

	@Pointcut("execution(* io.renren.modules.xm.service..*.add(..))")
	public void addPointcut(JoinPoint joinPoint){
		//获取目标方法的参数信息
		Object[] obj = joinPoint.getArgs();
		logger.debug(JSONObject.toJSONString(obj));
		logger.debug(JSONObject.toJSONString(obj[0]));

//		SuperEntity<?> entity =  (SuperEntity<?>) obj[0];
//		SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getSession()
//			.getAttribute(WebConfig.LOGIN_USER);

	}


	@Pointcut("execution(* io.renren.modules.xm.service..*.*(..))")
	public void insert(JoinPoint joinPoint){
		//获取目标方法的参数信息
		Object[] obj = joinPoint.getArgs();
		logger.debug(JSONObject.toJSONString(obj));
		logger.debug(JSONObject.toJSONString(obj[0]));

//		SuperEntity<?> entity =  (SuperEntity<?>) obj[0];
//		SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getSession()
//			.getAttribute(WebConfig.LOGIN_USER);

	}


	@Pointcut("execution(* io.renren.modules.xm.service..*.updateAllColumnById(..))")
	public void updateAllColumnById(JoinPoint joinPoint){
		//获取目标方法的参数信息
		Object[] obj = joinPoint.getArgs();
		logger.debug(JSONObject.toJSONString(obj));
		logger.debug(JSONObject.toJSONString(obj[0]));

//		SuperEntity<?> entity =  (SuperEntity<?>) obj[0];
//		SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getSession()
//			.getAttribute(WebConfig.LOGIN_USER);

	}

}
